/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hotel.visitor;

import java.security.Principal;
import java.util.Collection;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author DucNM
 * @email ducnm@vnpay.vn
 */
@Controller
public class AccessController {
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public ModelAndView login(ModelAndView model, Principal principal)
    {
        if (principal != null)
        {
            model = new ModelAndView("redirect:authenController.vn");
            return model;
        }
        model = new ModelAndView("login/index");
        return model;
    }

    @RequestMapping(value = "/logout", method = RequestMethod.GET)
    public String logout(ModelMap model, Principal principal)
    {
        if (principal != null)
        {
            return "logout";
        }
        return "login/login";
    }

    @RequestMapping(value = "/error/accessDenied", method = RequestMethod.GET)
    public ModelAndView accessDenied(ModelAndView model)
    {
        model = new ModelAndView("error/403");
        return model;
    }

    @RequestMapping(value = "/error/pageNotFound", method = RequestMethod.GET)
    public ModelAndView pageNotFound(ModelAndView model)
    {
        model = new ModelAndView("error/404");
        return model;
    }
}
